<?php
  /**
   * Actions
   */     
  if(isset($_GET['c']))
  {
    $controlerName = filter_input(INPUT_GET, 'c', FILTER_SANITIZE_STRING,FILTER_FLAG_STRIP_LOW|FILTER_FLAG_STRIP_HIGH);
    switch($controlerName)
    {
      case 'logoff':
        $_SESSION = array();//destroy the entire session
        header("Location: index.php");
        die();
      case 'import':
        include(APP_PATH.'app/mvc/c/import_c.php');
        die();
      case 'pod':
        die(PlayList::rss($_GET['pls']));
      case 'dlpod':
        if(PlayList::isPodcast($_GET['podcast'],$_GET['songId']))
        {
          $song = new Song($_GET['songId']);
          die($song->dl());
        }
        else
        {
          header("HTTP/1.0 404 Not Found");
          die();
        }
      case 'stream':
        if($_SESSION['MczSession']->can('play'))
        {
          session_write_close();
          $song = new Song($_GET['id']);
          $song->stream();
        }
        die();
      case 'dl':
        if($_SESSION['MczSession']->can('download'))
        {
          $song = new Song($_GET['songId']);
          die($song->dl());
        }
        die();
      case 'ajax': // ajax controller
        include(APP_PATH.'app/mvc/c/ajax_c.php');
        die();
      /**
       * Parse language file and creates js object
       */             
      case 'langjs':
        header("Content-Type: text/javascript");
        if(file_exists(APP_PATH.'app/lng/'.LANG_CODE.'.ini'))
        {
          $words = parse_ini_file(APP_PATH.'app/lng/'.LANG_CODE.'.ini');
        }
        else
        {
          $words = parse_ini_file(APP_PATH.'app/lng/en.ini');
        }
        Tools::conv_tabjs($words,'str');
        die();
      case 'dbg':
        if(APP_DEBUG)
        {
          echo('<pre>');
          var_dump($_SESSION);
          var_dump($_SERVER);
        }
        die();
      case 'phpinfo':
        if(APP_DEBUG)
        {
          phpinfo();
        }
        die();
      default:
        die();
    }
  }
  /**
   * If no action requested, display login or main page
   */     
  else
  {
    if(!$_SESSION['MczSession']->isAuth())
    {
      include(APP_PATH.'app/mvc/v/login_v.php');//login view
      die();
    }
    elseif($_SESSION['MczSession']->isAuth())
    {
      if(!isset($_SESSION['CueList']))// init cue list
      {
        $_SESSION['CueList'] = new CueList();
      }
      if(!isset($_SESSION['Search']))
      {
        $_SESSION['Search'] = new ResultSet();
      }
      include(APP_PATH.'app/mvc/v/main_v.php');
      die();
    }
  }
?>
